package br.com.academia.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.academia.dao.MatriculaDAO;
import br.com.academia.modelo.Matricula;

public class MatriculaExcluir extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public MatriculaExcluir() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		int id = Integer.parseInt(request.getParameter("id"));

		Matricula matricula = new Matricula();
		matricula.setIdmatricula(id);

		MatriculaDAO dao = new MatriculaDAO();

		out.print("<script language='javascript'>");
		if (dao.excluir(matricula)) {
			out.print("alert('Informacao Excluida!');");
		} else {
			out.print("alert('Erro!');");
		}
		out.print("location.href='/academia/menu/pre-matricula-listar.jsp'");
		out.print("</script>");

	}

}
